package com.yx.controller;

import com.yx.entity.GoodsEntity;
import com.yx.services.IGoodsService;
import com.yx.vo.Goods;
import com.yx.vo.StockParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname GoodsController
 * @Date 2021/07/08 16:06
 * @Author by yx
 * @Description TODO:
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    @GetMapping("/getGoodsList")
    public List<GoodsEntity> getGoodsList(){
        return goodsService.list();
    }

    @PostMapping("/addGoods")
    public GoodsEntity addGoods(@RequestBody GoodsEntity goods){
        boolean save = goodsService.save(goods);
        //返回的goods回填了id
        return goods;
    }

    @PostMapping("/updateGoods")
    public Boolean updateGoods(@RequestBody GoodsEntity goods){
        return goodsService.updateById(goods);
    }

    @GetMapping("/deleteGoods/{id}")
    public Boolean deleteGoods(@PathVariable("id") Integer id){
        return goodsService.removeById(id);
    }

    @GetMapping("/UpdateGoods/{id}")
    public GoodsEntity getGoodById(@PathVariable("id") Integer id){
        return goodsService.getById(id);
    }

    @PostMapping("/addGoodsAndStock")
    public Goods addGoodsAndStock(@RequestBody Goods goods){
        return goodsService.saveGoodsAndStock(goods);
    }




}
